#!/usr/bin/python

import sys
import os
import time
import shutil
import datetime

def poll():
	
	while True:
		os.system('''pkill -f 'python page_crawler.py' ''')	# clean up possibly zombie
		os.system('python page_crawler.py')
		backup_log()
		time.sleep(60)

def get_logtime():
	
	timer = datetime.datetime(1999, 1, 1)
	return timer.now().isoformat('.').replace('-', '').replace(':', '')

def backup_log(filename = 'ads.log', exceed_size = 4096 * 1024):

	size = os.stat(filename).st_size
	if size > exceed_size:
		logname = filename + get_logtime() + '.bak'
		shutil.move(filename, logname)

if __name__ == '__main__':

	poll()	
	#backup_log()
